package com.xue.zuoye;

import java.util.Scanner;

/*
*  6、分别在控制台输入字符串和子字符串，并计算
*      字符串中子字符串出现的次数。
* */
public class Task306 {
    public static void main(String[] args) {
        Count();
    }
    public static void Count(){
        System.out.println("请输入一个字符串::");
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();

        System.out.println("请输入需要统计的子字符串");
        String str1 = scanner.next();

        String str2 = "";
        int sum = 0;

        for(int i = 0;i<str.length();i++){
            if(str.charAt(i) == str1.charAt(0)){
                for(int j = i;j<str1.length();j++){
                    str2 = str2 + str.charAt(j);
                }
                sum++;
                i=i+str2.length()-1;
            }
        }
        System.out.println("字符串\""+str+"\"中有"+sum+"个\""+str1+"\"");
    }

}
